import { Item } from "../../shared/face/index";
import { BaseBody } from '../../core/rpg';
import { BagFuncResult } from './types';
import rpg_component from "../../component/rpg_component";
import { ComType } from "../../core/tool/component";
import { Skill, SkillUse } from "../../core/rpg/types";
import SkManager from "../../core/rpg/skill/SkManager";

/**
 * AddSkill 功能:加技能
 * @param useItem 使用的物品
 * @param useCount 使用数量
 * @param funcData 函数数据
 * @param player 玩家对象
 * @returns 使用结果
 */
export async function AddSkill(useItem: Item, useCount: number, funcData: any, player: BaseBody): Promise<BagFuncResult> {
    try {
        const skill = funcData as SkillUse;
        let com_rpg = player.getComponent(ComType.rpg) as rpg_component;
        com_rpg.addSk(skill);

        let _skData = SkManager.getSkillById(skill.skillId) as Skill;
        return {
            success: true,
            message: `技能${skill.desc || skill.reName || _skData.name}学习成功!`,
            data: { action: 'AddSkill' }
        };
    } catch (error: any) {
        return {
            success: false,
            message: '功能执行失败',
            data: { error: error.message }
        };
    }
}
